home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Disk / Directory / Init.c < prev    next >
Encoding:
Text File  |  1993-02-03  |  2.1 KB  |  118 lines  |  [TEXT/KAHL]

  1. //-- INIT.C
  2.  
  3. // This contains the code which initializes the sample application.
  4.  
  5. #include <stdio.h>
  6. #include "res.h"
  7. #include "struct.h"
  8. #include "error.h"
  9.  
  10.  
  11. MenuHandle applMenu,fileMenu,editMenu;
  12. unsigned char ColorQD,MultiWidget;        /* State flags */
  13.  
  14. #define TRAP_WNE    0x060
  15. #define TRAP_UNIMP    0x09F
  16.  
  17.  
  18. //-- Initialize Application --//
  19.  
  20. // The entry point for application initialization.
  21.  
  22. InitMacintosh()
  23. {
  24.     int i;
  25.  
  26.     InitToolbox();        // Step 1:  Initialize the macintosh.
  27.  
  28.     if (i = Catch())    // Step 2:    Trap errors; if a problem comes 
  29.     {                    //            up, simply exit to shell and
  30.         PostError(i);
  31.         ExitToShell();    //            forget it.
  32.     }
  33.  
  34.     InitEnv();            // Step 2:  Get environment stuff.
  35.     InitMenuBar();        // Step 3:  Initialize the menu bar.
  36.     InitGlobals();        // Step 4:  Initialize globals.
  37.     
  38.     Uncatch();            //Step 5:    All done.  Forget the error trap.
  39. }
  40.  
  41. //-- InitToolbox --//
  42.  
  43. // Bring up the Macintosh operating system as per Inside Macintosh.
  44.  
  45. InitToolbox()
  46. {
  47.     InitGraf(&qd.thePort);
  48.     InitCursor();
  49.     InitFonts();
  50.     InitWindows();
  51.     InitMenus();
  52.     TEInit();
  53.     InitDialogs(NULL);
  54.     FlushEvents(everyEvent,0);
  55. }
  56.  
  57. //-- InitEnv --//
  58.  
  59. // Get environment state.  The various things to test for include:
  60.  
  61. // •    Multifinder environment?
  62. // •    Color quickdraw present?.
  63.  
  64. InitEnv()
  65. {
  66.     SysEnvRec theWorld;
  67.     OSErr err;
  68.     short i;
  69.     Handle h;
  70.  
  71.     err = SysEnvirons(1,&theWorld);
  72.     if (theWorld.hasColorQD) ColorQD = 1;
  73.     else ColorQD = 0;
  74.  
  75.     if ((theWorld.machineType >= 0) && 
  76.         (NGetTrapAddress(TRAP_WNE,ToolTrap) != NGetTrapAddress(TRAP_UNIMP,ToolTrap)))
  77.         MultiWidget = 1;
  78.     else MultiWidget = 0;
  79. }
  80.  
  81.  
  82. //-- InitMenuBar --//
  83.  
  84. // Turn on the menu bar.
  85.  
  86. InitMenuBar()
  87. {
  88.     applMenu = GetMenu(APPLMENU);
  89.     AddResMenu(applMenu,'DRVR');
  90.     fileMenu = GetMenu(FILEMENU);
  91.     editMenu = GetMenu(EDITMENU);
  92.  
  93.     InsertMenu(applMenu,0);
  94.     InsertMenu(fileMenu,0);
  95.     InsertMenu(editMenu,0);
  96.  
  97.     DrawMenuBar();
  98. }
  99.  
  100.  
  101.  
  102. //-- InitGlobals --//
  103.  
  104. // Initialize any application globals:
  105.  
  106. // •    struct DrawWindow drawList.
  107.  
  108. InitGlobals()
  109. {
  110.     int i;
  111.     
  112.     drawList = (struct DrawWindow *)NewPtr(MAXWINDOWS * sizeof(struct DrawWindow));
  113.     if (drawList == NULL) Throw(INITOUTMEM);
  114.     for (i = 0; i < MAXWINDOWS; i++) drawList[i].inuse = 0;
  115.     
  116.     GetMounted();
  117. }
  118.